import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold_ohos/getx_scaffold_ohos.dart';

class TabLogic extends GetxController with BaseControllerMixin{

  /// 当前TAB索引
  int currentIndex = 0;

  /// 页面控制器
  late PageController pageController;

  @override
  void onInit() {
    pageController = PageController(initialPage: currentIndex, keepPage: true);
    super.onInit();
    eventListen<RefreshUiEvent>((data){
      if (Get.isDialogOpen == true || Get.isBottomSheetOpen == true || Get.isOverlaysOpen == true || Get.isSnackbarOpen == true){
        Get.back();
      }
      updateUi();
    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void updateIndex(int index) {
    currentIndex = index;
    pageController.jumpToPage(index);
    updateUi();
  }

  @override
  String get builderId => 'tab_view';
}
